/* ======================================================= */
/**
 * File   : ToolBar.java
 * Date   : 3 mars 2010 at 11:51:58
 */
/* ======================================================= */
package fr.isima.isipaint.gui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

import fr.isima.isipaint.controllers.ToolsController;
import fr.isima.isipaint.tools.ToolBox;

/* ======================================================= */
/**
 * 
 * @author Daniel
 * 
 */
/* ======================================================= */
public class ToolBar extends JPanel {

	/** Serial number */
	private static final long serialVersionUID = 1L;

	/** The width of one button */
	private static final int BUTTON_WIDTH = 25;

	/** The height of one button */
	private static final int BUTTON_HEIGHT = 25;

	/** The marge between icons */
	private static final int MARGE = 2;

	/** The tools set */
	private ToolBox tools;
	
	/** The listener */
	private ToolsController toolsCtrl;

	/**
	 * Default Constructor
	 */
	public ToolBar(ToolBox toolBox, ToolsController toolsCtrl) {
		this.tools = toolBox;
		this.toolsCtrl = toolsCtrl;
		setBorder(BorderFactory.createLineBorder(Color.black));
		setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

		/* To store the buttons */
		for (AbstractAction t : tools.getTools()) {
			JButton button = new JButton();
			button.setAction(t);
			button.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
			button.setText(""); // To only display the icon
			button.addActionListener(toolsCtrl);
			add(button);
			add(Box.createRigidArea(new Dimension(MARGE, 0)));
		}
	}

}
